package com.ztewatch.wearcontacts.receiver;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.widget.RemoteViews;

import com.ztewatch.wearcontacts.R;
import com.ztewatch.wearcontacts.WearContactCallLogActivity;

public class MissCallNotifyReceiver extends BroadcastReceiver {
	public static final String CALL_NOTIFY_ACTION = "android.intent.action.MissCall_Nofity";
	private NotificationManager manager;
	private static final int NOTIFICATION_ID = 1;

	@Override
	public void onReceive(Context context, Intent intent) {
		manager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);

		if (CALL_NOTIFY_ACTION.equals(intent.getAction())) {
			showCustomView(context);
		}
	}

	private void showCustomView(Context context) {
		RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
				R.layout.miss_call_custom_notification);
		Intent intent = new Intent(context, WearContactCallLogActivity.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
				intent, 0);
		remoteViews.setOnClickPendingIntent(R.id.misscall_ok, pendingIntent);
		NotificationCompat.Builder builder = new Builder(context);
		builder.setContent(remoteViews);
		manager.notify(NOTIFICATION_ID, builder.build());
	}

}
